package com.htht.smartschool.action.fence;

import java.util.List;

import com.htht.smartschool.action.baseaction.BaseAction;
import com.htht.smartschool.common.model.ParamData;
import com.htht.smartschool.common.servlet.DataContainer;
import com.htht.smartschool.model.fence.TFence;
import com.htht.smartschool.model.tschool.TSchool;
import com.htht.smartschool.service.fence.FenceService;
import com.htht.smartschool.util.system.GsonUtils;

public class FenceAction extends BaseAction{

	@Override
	public boolean processData(DataContainer obj, ParamData pd) {
		boolean flag = false;
		FenceService fenceService = new FenceService();
		TFence fence = (TFence) GsonUtils.getInstance().fromJson(pd.getData(), TFence.class);
		if(pd.getCmd().equalsIgnoreCase("getFenceByStudentCode")){
			List<TFence> list = fenceService.getFenceByStudentCode(fence);
			if(list.size() > 0){
				flag = true;
				obj.setData(list);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getFenceByStudentImei")){
			TFence reuslt = fenceService.getFenceByStudentImei(fence);
			if(reuslt!=null){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("添加学生围栏失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("addFenceByStudentCode")){
			boolean reuslt = fenceService.addFenceByStudentCode(fence);
			if(reuslt){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("添加学生围栏失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("initFences")){
			boolean reuslt = fenceService.initFences(fence);
			if(reuslt){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("添加学校围栏失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("updateFenceByStudentCode")){
			boolean reuslt = fenceService.updateFenceByStudentCode(fence);
			if(reuslt){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("修改学生围栏失败！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("getSchoolFenceByStudentCode")){
			TSchool reuslt = fenceService.getSchoolFenceByStudentCode(fence.getStudentcode());
			if(reuslt != null){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("查无数据！");
			}
		}else if(pd.getCmd().equalsIgnoreCase("deleteFenceByStudentCode")){
			boolean reuslt = fenceService.deleteFenceByStudentCode(fence);
			if(reuslt){
				flag = true;
				obj.setData(reuslt);
			}else{
				obj.setData("删除学生围栏失败！");
			}
		}
		
		return flag;
	}

}
